#include "WPointerTest.h"
#include <iostream>
#include <memory>

using namespace std;

class  WPtrTestBase
{
public:
	 WPtrTestBase();
     virtual ~ WPtrTestBase();

private:

};

 WPtrTestBase:: WPtrTestBase()
{
     cout << "construct:WPtrTestBase" << endl;
}

 WPtrTestBase::~ WPtrTestBase()
{
     cout << "deconstruct:~WPtrTestBase" << endl;
}


 class WPtrTestChild :public WPtrTestBase
 {
 public:
     WPtrTestChild();
     ~WPtrTestChild() override;

 };

 WPtrTestChild::WPtrTestChild()
 {
     cout << "construct:WPtrTestChild" << endl;
 }

 WPtrTestChild::~WPtrTestChild()
 {
     cout << "deconstruct:~WPtrTestChild" << endl;
 }


 class F {};
 class G : public F {};


void WPointerTest::Test()
{
    cout << "BEGIN--------------WPointerTest::Test------------"<<endl;
    std::unique_ptr< WPtrTestBase> ptr = make_unique< WPtrTestChild>();
    
    cout << "BEGIN--------Test Share Ptr------------"<<endl;
    std::shared_ptr<WPtrTestBase> * shr_ptr = make_shared<WPtrTestChild>();
    std::cout <<"use_count:"<< shr_ptr->use_count()<<std::endl;

    std::shared_ptr<WPtrTestChild> ptr2 = shr_ptr;
    cout << "END----------Test Share Ptr------------"<<endl;


    cout << "END----------------WPointerTest::Test------------" << endl;
}

void WPointerTest::TestUniquePtr()
{
    std::unique_ptr<int> int_ptr0(new int(5));
}

void WPointerTest::TestSharePtr()
{
    // Test Construct
    shared_ptr<G> sp0(new G);   // okay, template parameter G and argument G*
    shared_ptr<G> sp1(sp0);     // okay, template parameter G and argument shared_ptr<G>
    shared_ptr<F> sp2(new G);   // okay, G* convertible to F*
    shared_ptr<F> sp3(sp0);     // okay, template parameter F and argument shared_ptr<G>
    shared_ptr<F> sp4(sp2);     // okay, template parameter F and argument shared_ptr<F>
   // shared_ptr<int> sp5(new G); // error, G* not convertible to int*
   // shared_ptr<int> sp6(sp2);   // error, template parameter int and argument shared_ptr<F>
}


